﻿/*========================================================================
	TASK 5:                                                        {Arrays}
	Write a program that finds the maximal increasing sequence in an array.
    Example:{3, 2, 3, 4, 2, 2, 4} => {2, 3, 4}.
=========================================================================*/

using System;

class MaximalIncreasingSequence
{
    static void Main()
    {
        int[] array = { 3, 6, 2, 3, 4, 2, 2, 4, 2, 3, 4, 5, 8, 9 };

        int length = 1;
        int maxLength = 1;
        int start = 0;
        int maxStart = 0;

        for (int index = 0; index < array.Length - 1; index++)
        {
            if (array[index + 1] == array[index] + 1)
            {
                length++;

                if (length > maxLength)
                {
                    maxLength = length;
                    maxStart = start;
                }
            }
            else
            {
                length = 1;
                start = index + 1;
            }
        }

        for (int i = maxStart; i < maxStart + maxLength; i++)
        {
            Console.Write(array[i] + " ");
        }
        Console.WriteLine();
    }
}

